package libs

import (
	toml "github.com/BurntSushi/toml"
)

type Database struct {
	Host   string
	Port   int
	DB     string
	Driver string
	Username string
	Password string
}
type DBConfig struct {
	Servers map[string]Database
}

type Redis struct {
	Host     string
	Port     int
	DB       int
	Password string
}
type RedisConfig struct {
	Servers map[string]Redis
}

type ServerItem struct {
	Port int
}
type ServerConfig struct {
	Servers map[string]ServerItem
}

func NewDBConfig(path string) (*DBConfig, error) {
	var config DBConfig
	var err error
	if _, err = toml.DecodeFile(path+"/database.toml", &config); err == nil {
		return &config, nil
	}
	return nil, err
}

func NewRedisConfig(path string) (*RedisConfig, error) {
	var config RedisConfig
	var err error
	if _, err = toml.DecodeFile(path+"/redis.toml", &config); err == nil {
		return &config, nil
	}
	return nil, err
}

func NewServerConfig(path string) (*ServerConfig, error) {
	var config ServerConfig
	var err error
	if _, err = toml.DecodeFile(path+"/servers.toml", &config); err == nil {
		return &config, nil
	}
	return nil, err
}
